﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Collections.Specialized;

namespace DataAccess
{
    public abstract  class  DataAccess<T>
    {
        #region ConnectionString  
        protected  string strConn;
        /// <summary>
        /// 
        /// </summary>
        public  string ConnectionString
        {
            get
            {
               // return Framework.Properties.Settings.Default.NorthwindConnectionString;
                return strConn;
            }
            set 
            {
                strConn = value;
            }
        }
        #endregion

        #region Filters & Sorters
        //齬唗睿徹薦濬﹝
        protected AccessFilter filter = new AccessFilter();
        protected AccessSorter sorter = new AccessSorter();

        public AccessFilter Filter
        {
            get
            {
                return this.filter;
            }
        }

        public AccessSorter Sorter
        {
            get
            {
                return this.sorter;
            }
        }
        #endregion //Filters & Sorters

        #region Pager
        //煦珜髡夔窒煦﹝
        protected int pageSize = Int32.MaxValue;
        protected int pageIndex = 1;
        protected int totalCount = 0;

        /// <summary>
        /// 珜唗瘍﹝
        /// </summary>
        public int PageIndex
        {
            get { return this.pageIndex; }
            set { this.pageIndex = value; }
        }

        /// <summary>
        /// 藩珜珆尨腔沭醴杅講﹝
        /// </summary>
        public int PageSize
        {
            get { return this.pageSize; }
            set { this.pageSize = value; }
        }

        /// <summary>
        /// 軞珜杅
        /// </summary>
        public int PageCount
        {
            get { return ((this.totalCount - 1) / this.pageSize) + 1; }
        }

        /// <summary>
        /// 軞沭醴杅﹝
        /// </summary>
        public int TotalCount
        {
            get { return this.totalCount; }
            set { this.totalCount = value; }
        }
        #endregion //Pager

        public DataAccess() { this.ConnectionString = DataAccess.Properties.Settings.Default.SammoMISConnectionString; }
        public DataAccess(string strConnectionString)
        { this.ConnectionString = strConnectionString; }

        #region "Search"

        public abstract EntityCollection<T> SearchEntityList(Type type);
        public abstract EntityCollection<T> Select(string strbusinessEntity, NameValueCollection combine, out int totalCount, int pageSize, int pageIndex);
        #endregion
     
        #region "modify"
     public  abstract bool Insert(T entity);
     public abstract bool Insert(T[] entitys);
     public abstract bool InsertBySp(T entity);
     public abstract bool Update(T entity);
     public abstract bool Update(T[] entitys);
     public abstract bool UpdateBySP(T entity);
     public abstract bool Delete(T entity);
     public abstract bool DeleteBySP(T entity);
        #endregion

    }
}
